#include "rtwtypes.h"
#include "Alarm_nonRecov_sys.h"

#define bms_Slave_IN_Err_p             ((uint8_T)1U)
#define bms_Slave_IN_NO_ACTIVE_CHILD_f ((uint8_T)0U)
#define bms_Slave_IN_Name              ((uint8_T)2U)

void Alarm_nonRecov_sys_Init(boolean_T *rty_Alarm_flg)
{
  *rty_Alarm_flg = false;
}

void Alarm_nonRecov_sys_Reset(boolean_T *rty_Alarm_flg, DW_Alarm_nonRecov_sys_T *
  localDW)
{
  localDW->is_active_c1_Bms_lib = 0U;
  localDW->is_c1_Bms_lib = bms_Slave_IN_NO_ACTIVE_CHILD_f;
  localDW->count = 0U;
  *rty_Alarm_flg = false;
}

void Alarm_nonRecov_sys(boolean_T rtu_Err_flg, uint16_T rtu_Alarm_time,
  boolean_T *rty_Alarm_flg, DW_Alarm_nonRecov_sys_T *localDW)
{
  if (localDW->is_active_c1_Bms_lib == 0U) {
    localDW->is_active_c1_Bms_lib = 1U;
    localDW->is_c1_Bms_lib = bms_Slave_IN_Name;
    *rty_Alarm_flg = false;
    localDW->count = 1U;
  } else if (localDW->is_c1_Bms_lib == bms_Slave_IN_Err_p) {
    *rty_Alarm_flg = true;
  } else {
    *rty_Alarm_flg = false;
    if (rtu_Err_flg && (localDW->count >= rtu_Alarm_time)) {
      localDW->is_c1_Bms_lib = bms_Slave_IN_Err_p;
      *rty_Alarm_flg = true;
    } else if (rtu_Err_flg) {
      if (localDW->count >= rtu_Alarm_time) {
        localDW->count = rtu_Alarm_time;
      } else {
        localDW->count++;
      }
    } else {
      localDW->count = 1U;
    }
  }
}
